<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<title>子账号管理</title>
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
    
		<script>
		var orgId='${org.orgId}';
		var mainUserId = '${mainUserId}';
		$(function(){
			$('#userList').datagrid({
				title:'子账号信息列表',
				iconCls:'icon-ok',
				fitColumns:true,
				nowrap:false,
				singleSelect:true,
				rownumbers:true,
				animate:true,
				collapsible:true,
				pagination:true,
				pageSize:15,
				pageList:[15,20,30],
				url:'${ctx}/crm/user/list!data.action?filter_mainUserId='+mainUserId,
				idField:'tabId',
				columns:[[
		             {field:'subUserId',title:'用户Id',width:100},
	                 {field:'subUserEname',title:'登录名称',width:100}
				]],
				toolbar:[					
		          {
		              	text:'增加用户及关联',
			              iconCls:'icon-add',
			              handler:function(){save();}
		          }
		          ,'-',
		          {
		              text:'删除关联',
		              iconCls:'icon-cut',
		              handler:function(){del();}
		          }
// 		            ,'-',
// 		          {
// 		              text:'修改',
// 		              iconCls:'icon-edit',
// 		              handler:function(){edit();}
// 		          }
		          ,'-',
		          {
		              text:'刷新',
		              iconCls:'icon-reload',
		              handler:function(){
		                  reload();
		             }
		          }
		        ]
			});
		});	

	
		//查询
		 function searchList(){			
	    	var queryParams = $('#userList').datagrid('options').queryParams;	    
	       	var opt = $('#userList').datagrid('options'); 
	        $('#userList').datagrid('options').pageNumber=1;
	        queryParams["filter_subUserEname"] = $('#subUserEname').val();
	        queryParams["filter_mainUserId"] = mainUserId;
	        $('#userList').datagrid('reload');
	        var page = $('#userList').datagrid('getPager');
			page.pagination({pageNumber:1,pageSize:opt.pageSize});
		 }
		 //清除查询
		 function clearSearch(){					
		    $('#subUserEname').val('');
		 }
		
		//保存
		function save(){
			$('#userAddFrame').html('');
			var url = '${ctx}/crm/user/add.action?mainUserId='+mainUserId;
			$('#userAddFrame').attr("src",url);
			$('#userAddWin').window('setTitle',"添加子账号信息");	
			$('#userAddWin').window('open');				
		}
		
		//重新加载数据
		function reload(){
			$('#userList').datagrid('reload');
		}
		
		
          //删除方法
		function del(){
			var obj = getSelected();
			if(obj){
				$.messager.confirm('确认','确定要删除: <font color=red><b>'+obj.subUserEname+'</b></font> ?',function(flag){  
			        if(flag){  
			            $.ajax({
						  url: '${ctx}/crm/user/del.action',
						  type: 'POST',
						  cache: false,
						  data: 'id='+obj.tabId,
						  success: function(data){
						  	var oTxt = jQuery.parseJSON(data);
						    var mess = oTxt.msg;	
							var flag = oTxt.flag;
					        if(flag=="T"){
								$.messager.alert('提示',mess, 'info',function(){
								   reload();
								});
							}else{
								$.messager.alert('提示',mess, 'error');
							}
						  }
						});
			        }  
			     });
			  }
		  }
		  
		  //取得数据
		  function getSelected(){
		  	var rec = $('#userList').datagrid('getSelected');
		  	if(rec){
		  		return rec;
		  	}else{
		  		$.messager.alert('提示',"请选择需要操作记录!", 'info');
		  		return null;
		  	}
		  }
		  
		   //关闭win
		 function closeWin(){
		 	$('#userAddWin').window('close');	
		 }
		
	     
	</script>
</head>
<body>
<div title="查询"  class="easyui-panel" icon="icon-search"  collapsible="false">
		<table class="datagrid-body" width="100%">
			<tr>
				<td class="datagrid-header">登录名称</td>
				<td width="18px;"><input type="text" class="easyui-validatebox" id="subUserEname"  name="subUserEname" size="30" value=""/></td>
				
				<td><a class="easyui-linkbutton" iconCls="icon-search" onclick="searchList()">查 询</a>
				<a class="easyui-linkbutton" iconCls="" href="javascript:void(0)" onclick="clearSearch();">清空</a>
				</td>
			</tr>
		</table>
		</div>
	<table id="userList"></table>
	<div id="userAddWin" class="easyui-window" title="客户信息" style="padding:5px;width:350px;height:400px; overflow: hidden;" align="center"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 	<iframe frameborder="0"  id="userAddFrame" height="100%" width="100%" scrolling="Yes" frameborder="0" ></iframe>
    </div>

</body>
</html>